import { defineConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'

function pathResolve(dir) {
  return resolve(__dirname, '.', dir)
}

export default defineConfig({
  base: '',
  plugins: [vue()],
  resolve: {
    alias: {
      '@': pathResolve('src'),
    },
  },
  optimizeDeps: {
    include: ['axios'],
  },
  build: {
    target: 'modules',
    outDir: 'dist',
    assetsDir: 'assets',
    minify: 'terser', // 混淆器
  },
  server: {
    open: true,
    port: '8000',
    proxy: {
      // 把key的路径代理到target位置
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      ['/api/v1']: {
        // 需要代理的路径   例如 '/api'
        target: 'http://localhost:8080/',
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^'), ''),
      },
    },
  },
  define: {
    'process.env': {},
  },
})
